package com.kinghood.infrastructure.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.kinghood.infrastructure.model.constant.ExceptionConstant;
import lombok.*;

import java.io.Serializable;

/**
 *   深圳金雅福控股集团有限公司
 * @author zhangfanjun
 * @date 2022/4/7
 */
@Builder
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
public class KingHoodResponseVO<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    private Integer code;
    private Boolean success;
    private String message;
    private String error;
    private T data;

    /**
     * 请求成功，无数据实体返回
     */
    public static <T> KingHoodResponseVO<T> success() {
        return KingHoodResponseVO.<T>builder()
                .code(ExceptionConstant.CODE_SUCCESS)
                .success(true)
                .message("成功")
                .build();
    }
    /**
     * 请求成功，返回数据
     */
    public static <T> KingHoodResponseVO<T> success(T data) {
        return KingHoodResponseVO.<T>builder()
                .code(ExceptionConstant.CODE_SUCCESS)
                .success(true)
                .message("成功")
                .data(data)
                .build();
    }
    /**
     * 请求失败并返回数据
     */
    public static <T> KingHoodResponseVO<T> fail(Integer code, String message, T data) {
        return KingHoodResponseVO.<T>builder()
                .code(code)
                .success(false)
                .message(message)
                .data(data)
                .build();
    }

    /**
     * 请求失败并返回信息
     */
    public static <T> KingHoodResponseVO<T> fail(Integer code, String message) {
        return KingHoodResponseVO.<T>builder()
                .code(code)
                .success(false)
                .message(message)
                .data(null)
                .build();
    }

    /**
     * 请求失败并返回信息
     */
    public static <T> KingHoodResponseVO<T> error(Integer code, String message,String error) {
        return KingHoodResponseVO.<T>builder()
                .code(code)
                .success(false)
                .message(message)
                .error(error)
                .data(null)
                .build();
    }

    /**
     * 请求失败并返回编码
     */
    public static <T> KingHoodResponseVO<T> failCode(Integer code) {
        return KingHoodResponseVO.<T>builder()
                .code(code)
                .success(false)
                .build();
    }
    /**
     * 请求失败并返回编码
     */
    public static <T> KingHoodResponseVO<T> fail(String message) {
        return KingHoodResponseVO.<T>builder()
                .code(ExceptionConstant.CODE_BAD_SERVER)
                .success(false)
                .message(message)
                .build();
    }

    /**
     * 微服务熔断
     */
    public static <T> KingHoodResponseVO<T> fallback() {
        return KingHoodResponseVO.<T>builder()
                .code(ExceptionConstant.CODE_FALLBACK)
                .success(false)
                .message("服务繁忙，稍后重试")
                .build();
    }

}
